import { nextTick } from "../utils"

// 用来记录watcher
let quere = []
let has = {}
function flushSchedulerQuere() {
  for (let i = 0; i < quere.length; i++) {
    quere[i].get()
  }
  quere = []
  has = {}
  pending = false
}

let pending = false
export function quereWatcher(watcher) {
  const id = watcher.id
  if (!has[id]) {
    console.log(quere)
    quere.push(watcher)
    has[id] = true
    // quere[0].get() 如果不异步，只会更新第一个数据
    // Promise.resolve().then(flushSchedulerQuere)
    // 遇到第一个数据触发set既进入
    nextTick(flushSchedulerQuere)
    pending = true
  }
}